//
//  MKNewsChatLatelyCell.swift
//  MOKOAnnounce
//
//  Created by 曹相召 on 2017/7/10.
//  Copyright © 2017年 cc.moko. All rights reserved.
//

import UIKit

class MKNewsChatLatelyCell: MKBaseTableViewCell {

    var icon:UIImageView!
    var count:UILabel!
    var name:UILabel!
    var tip:UILabel!
    var time:UILabel!
    var line:UIView!
    var notSend:UIImageView!
    
    var lineHiden:Bool!
    
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.makeUI()
    }
    func makeUI() -> Void {
        self.icon = UIImageView.init()
        self.icon.image = UIImage.init(named: "logo55X66")
        self.icon.backgroundColor = UIColor.red
        self.contentView.addSubview(self.icon)
        
        self.name = UILabel.label(fontSize: 16, textColor: UIColorFromRGB(rgbValue: 0x333333, A: 1))
        self.name.text = "美空小美"
        self.contentView.addSubview(self.name)
        
        self.tip = UILabel.label(fontSize: 12, textColor: UIColorFromRGB(rgbValue: 0x999999, A: 1))
        self.tip.text = "[么么哒]"
        self.contentView.addSubview(self.tip)

        self.count = UILabel.label(fontSize: 10, textColor: UIColor.white)
        self.count.text = "5"
        self.count.textAlignment = .center
        self.count.backgroundColor = UIColorFromRGB(rgbValue: 0xff0051, A: 1)
        self.contentView.addSubview(self.count)
        
        self.time = UILabel.label(fontSize: 12, textColor: UIColorFromRGB(rgbValue: 0x999999, A: 1))
        self.time.text = "11:22"
        self.contentView.addSubview(self.time)
        
        self.line = UIView.init()
        self.line.backgroundColor = UIColorFromRGB(rgbValue: 0xe5e5e5, A: 1)
        self.contentView.addSubview(self.line)
        
        self.notSend = UIImageView.init()
        self.notSend.image = UIImage.init(named: "newChat_draft_select")
        self.contentView.addSubview(self.notSend)
    }
    
    func config(icon:String,count:Int,name:String,lineHiden:Bool) -> Void {
        
        self.icon.image = UIImage.init(named: icon)
        self.name.text = name
        self.count.isHidden = count <= 0
        if(count > 99){
            self.count.text = "N"
        }else{
            self.count.text = String.init(stringInterpolationSegment: count)
        }
        self.lineHiden = lineHiden
        self.setNeedsLayout()
    }
    override func layoutSubviews() {
        super.layoutSubviews()
        self.icon.frame = CGRect.init(x: 10, y: (self.contentView.height - 50) * 0.5, width: 27.5 * 5.0 / 3.0, height: 50)
        
        self.name.sizeToFit()
        self.name.frame = CGRect.init(x: self.icon.right + 10, y: 14, width: self.name.width, height: self.name.height)
        
        self.tip.sizeToFit()
        self.tip.frame = CGRect.init(x: self.icon.right + 10, y: self.name.bottom + 10, width: self.tip.width, height: self.tip.height)
        
        self.time.sizeToFit()
        self.time.frame = CGRect.init(x: self.contentView.right - 10 - self.time.width, y: 14, width: self.time.width, height: self.time.height)
        
        self.count.frame = CGRect.init(x: self.icon.right - 7.5, y: self.icon.top - 7.5, width: 15, height: 15)
        self.count.layer.cornerRadius = 7.5
        self.count.clipsToBounds = true
        

        self.line.frame = CGRect.init(x: 10, y: self.contentView.height - 0.5, width: self.contentView.width - 10, height: 0.5)
    }
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }


}
